<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>
<style>
    .s {
        clear: both;
        margin-top: 10px
    }
    .layui-form-select dl { max-height:180px; }
</style>

<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

                        <ul class="layui-tab-title">
                            <li class="" onclick="go('company')">所有公司</li>
                            <li class="layui-this" onclick="">添加公司</li>
                        </ul>

                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">
                            <div class="layui-tab-item layui-show" style="padding-top: 15px">
                                <form class="layui-form " action="">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">公司名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="company" value="" class="layui-input"
                                                   lay-verify="required" placeholder="请输入">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">地址</label>
                                        <div class="layui-input-block">
                                            <select name="address" lay-verify="required" size=3>
                                                <option value=""></option>
                                                {volist name="city" id="data"}
                                                <option value={$data.city_name}>{$data.city_name}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">手机号</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="tel" value="" class="layui-input"
                                                   lay-verify="required" placeholder="请输入">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <label class="layui-form-label">公司logo</label>
                                        <div class="layui-input-block " style="width: auto;">
                                            <div class="layui-upload-drag" id="pic1" style="padding: 2px">
                                                <img class="layui-upload-img"
                                                     style="width: 120px;height: 120px; object-fit: cover;"
                                                     src="/res/img/thumb.png">
                                                <input type="hidden" name="logo" value=""
                                                       lay-verify="required">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label"></label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" id="is_show" name="is_show" lay-skin="primary"
                                                   value="1"
                                                   title="展示" checked>
                                        </div>
                                    </div>

                                    <div class="layui-form-item form-footer2">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="company">确认添加</button>
                                            <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                                        </div>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>

    var app = new Vue({
        el: '#app',
    });

    layui.use(['form', 'upload', 'laydate'], function () {
        var $ = layui.$
            , layer = layui.layer
            , form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;

        //图片上传
        upload.render({
            elem: '#pic1'
            , url: '/tool/qiniu/upload'
            , before: function () {
                layer.load(2);
            }
            , done: function (res) {
                layer.closeAll();
                $('#pic1 img').attr('src', res.data.url);//完整url
                $('#pic1 input').val(res.data.pic);//存入数据库中的部分url
            }
        });

        //监听submit提交
        form.on('submit(company)', function (obj) {

            $.post("{:url('add_company')}", {data: obj.field}, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1});
                    $('#pic1 img').attr('src', '/res/img/thumb.png');
                    $('.layui-form')[0].reset();
                    return false;
                } else {
                    layer.msg(res.msg, {icon: 2}, function () {
                    })
                    return false;
                }

            });
            return false;
        });
    });
</script>

<script type="text/javascript" src="/res/js/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="/res/js/plupload/i18n/zh_CN.js"></script>
<script type="text/javascript" src="/res/js/qiniu.js"></script>
